from django.shortcuts import render,HttpResponse,redirect

# Create your views here.

# from utils.sms import send_sms_single


def send_sms(request):
    pass
    # if request.method == "GET":
    #     res=send_sms_single('15203664920',1138960,[6666,])
    #     if res['result'] == 1000:
    #         return HttpResponse(res['errmsg'])
    #     else:
    #         return HttpResponse('cheng gong')


from django import forms
from app01 import models
from django.core.validators import RegexValidator  # 导入对象
class RegisterModelForm(forms.ModelForm):
    # mobile = forms.CharField(label='手机号',validators=[RegexValidator(r'^(1[3|4|5|6|7|8|9])\d{9}$','手机号格式错误')],widget=forms.TextInput(attrs={'class':'form-control','placeholder':'请重复输入手机号'}))
    # password = forms.CharField(widget=forms.PasswordInput(attrs={'class':'form-control','placeholder':'请输入密码'}))
    # confirm_password = forms.CharField(label='重复密码',widget=forms.PasswordInput(attrs={'class':'form-control','placeholder':'请重复输入密码'}))
    # code = forms.CharField(label='验证码',widget=forms.TextInput(attrs={'class':'form-control','placeholder':'请重复输入验证码'}))
    #
    mobile = forms.CharField(label='手机号',validators=[RegexValidator(r'^(1[3|4|5|6|7|8|9])\d{9}$','手机号格式错误')])
    password = forms.CharField(label='密码')
    confirm_password = forms.CharField(label='重复密码')
    code = forms.CharField(label='验证码')
    class Meta:
        model = models.UserInfo
        # fields = '__all__'  # 写成__all__页面的字段显示按照models里面顺序排列
        fields = ['username','email','password','confirm_password','mobile','code']
    def __init__(self,*args,**kwargs):
        super(RegisterModelForm,self).__init__(*args,**kwargs)

        for name,field in self.fields.items():  # name是字段，field是字段类型
            field.widget.attrs['class'] = 'form-control'
            field.widget.attrs['placeholder'] = '请输入%s' % (field.label,)


def register(request):

    if request.method == "GET":
        form = RegisterModelForm()
        return render(request, 'app01/register.html', {'form':form})

